import urllib2,time,os

'''

cdb_cookietime
2592000
bbs.stage1st.com/
1536
4263359488
29925647
1353108992
29852348
*
cdb_sid
6H0aGJ
bbs.stage1st.com/
1536
2413115520
29853630
850388992
29852348
*
cdb_auth
z4OQokoa%2BIqZMk%2FDNiqV%2FXuIUK7dY%2FHRNuBJX5ew4ciHT%2FPhSDxgjDfLj%2F2ZbtU
bbs.stage1st.com/
1536
2109436928
29858257
1353308992
29852348
*
cdb_visitedfid
8D27
bbs.stage1st.com/
1536
3679436928
29858257
2939088992
29852348
*


GET /index.php HTTP/1.1
Accept: */*
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)
Host: bbs.stage1st.com
Connection: Keep-Alive
Cookie: cdb_cookietime=2592000; cdb_sid=6H0aGJ; cdb_auth=z4OQokoa%2BIqZMk%2FDNiqV%2FXuIUK7dY%2FHRNuBJX5ew4ciHT%2FPhSDxgjDfLj%2F2ZbtU; cdb_visitedfid=8D27


'''


req = urllib2.Request('http://bbs.stage1st.com/')
req.add_header('Accept', '*/*')
req.add_header('User-Agent', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)')
req.add_header('Connection', 'Keep-Alive')
req.add_header('Cookie', 'cdb_cookietime=2592000; cdb_sid=6H0aGJ; cdb_auth=z4OQokoa%2BIqZMk%2FDNiqV%2FXuIUK7dY%2FHRNuBJX5ew4ciHT%2FPhSDxgjDfLj%2F2ZbtU; cdb_visitedfid=8D27')

timer = 50
while 1:
      time.sleep(10)
      try:
	r = urllib2.urlopen(req) 
	timer = timer - 1
	if timer == 0:
	    timer = 50
	    a = open(os.curdir+'\\s1lastrecord.txt','w')
	    a.write(r.readlines())
	    a.close()
      except Exception:
        a = open('s1foreverlog.txt','r+')
	info = '%s something wrong..' % (str(time.localtime()),)
	print info
	a.write(info)
	a.close()
	continue
       
